package num260;

import java.util.HashMap;

/**
 * 260. 只出现一次的数字 III
 * 题目：https://leetcode-cn.com/problems/single-number-iii/
 * 三叶姐题解: https://leetcode-cn.com/problems/single-number-iii/solution/gong-shui-san-xie-yi-ti-shuang-jie-ha-xi-zgi4/
 * <p>
 * 哈希表
 */
class Solution {
    public int[] singleNumber(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i : nums) {
            map.put(i, map.getOrDefault(i, 0) + 1);
        }
        int[] ans = new int[2];
        int idx = 0;
        for (int i : nums) {
            if (map.get(i) == 1) {
                ans[idx++] = i;
            }
        }
        return ans;
    }
}
